package com.spring.boot.controller;

import com.spring.boot.entity.Insured;
import com.spring.boot.service.InsuredService;
import com.spring.boot.vo.QueryRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author: ZTQ
 * @Date: 2021/01/01 17:26
 * @Description: TODO 被保险人信息管理 控制器
 * @Version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/insured")
public class InsuredController {
    @Autowired
    private InsuredService insuredService;

    /**
     * @param insured 被保险人对象
     * @description: 添加被保险人
     */
    @PostMapping(value = "/addInsured", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> addUser(@RequestBody Insured insured) {
        //调用insuredService层的addInsured方法，进行新增被保险人操作
        Map<String, Object> stringObjectMap = insuredService.addInsured(insured);
        //返回数据信息
        return stringObjectMap;
    }


    /**
     * @param insured 被保险人对象
     * @description: 修改被保险人
     */
    @PostMapping(value = "/updateInsured", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> updateUser(@RequestBody Insured insured) {
        //调用用户insuredService层的updateInsured方法，进行修改被保险人操作
        Map<String, Object> stringObjectMap = insuredService.updateInsured(insured);
        //返回数据信息
        return stringObjectMap;
    }

    /**
     * @param id 被保险人id
     * @description: 批量删除被保险人
     */
    @GetMapping(value = "/deleteBatchIdsInsured", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> deleteBatchIdsUser(@RequestParam String id) {
        //调用insuredService层的deleteBatchIdsInsured方法，进行修改被保险人操作
        Map<String, Object> stringObjectMap = insuredService.deleteBatchIdsInsured(id);
        //返回数据信息
        return stringObjectMap;
    }


    /**
     * @param insured 被保险人对象
     * @description: 根据关键字 筛选查询被保险人信息
     */
    @GetMapping(value = "/getInsuredList",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> getUserList(QueryRequest queryRequest, Insured insured){
        //调用insuredService层的findInsuredList方法，进行根据关键字进行筛选查询操作
        Map<String, Object> insuredList = insuredService.findInsuredList(queryRequest, insured);
        //返回数据信息
        return insuredList;
    }

    /**
     * @param uid 用户id
     * @description: 根据uid查询被保险人信息
     */
    @GetMapping(value = "/findInsuredListByUid",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> findInsuredListByUid(@RequestParam String uid){
        //调用insuredService层的findInsuredListByUid方法，进行根据用户id查询被保险人信息操作
        Map<String, Object> insuredListByUid = insuredService.findInsuredListByUid(uid);
        //返回数据信息
        return insuredListByUid;
    }

    /**
     * @param id 被保险人id
     * @description: 根据id查询被保险人信息
     */
    @GetMapping(value = "/findInsuredById",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> findInsuredById(@RequestParam String id){
        //调用insuredService层的findInsuredById方法，进行根据用户id查询被保险人信息操作
        Map<String, Object> insuredListByUid = insuredService.findInsuredById(id);
        //返回数据信息
        return insuredListByUid;
    }

}
